//
//  XHQBasicVC.m
//  tabbarTest
//
//  Created by 徐汉卿 on 16/5/23.
//  Copyright © 2016年 Kevin. All rights reserved.
//

#import "XHQBasicVC.h"

@interface XHQBasicVC ()

@end

@implementation XHQBasicVC






//tree


#define FirstStep UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];\
UIImageView *fromImageView;\
UIImageView *toImageView;\
UIGraphicsBeginImageContextWithOptions(self.navigationController.view.bounds.size, NO, [UIScreen mainScreen].scale);\
[self.navigationController.view.layer renderInContext:UIGraphicsGetCurrentContext()];\
UIImage *fromImage = UIGraphicsGetImageFromCurrentImageContext();\
UIGraphicsEndImageContext();\
fromImageView = [[UIImageView alloc] initWithImage:fromImage];\
fromImageView.frame = self.navigationController.view.frame;\
[window addSubview:fromImageView]

#define SecondStep UIGraphicsBeginImageContextWithOptions(self.navigationController.view.bounds.size, NO, [UIScreen mainScreen].scale);\
[self.navigationController.view.layer renderInContext:UIGraphicsGetCurrentContext()];\
UIImage *toImage = UIGraphicsGetImageFromCurrentImageContext();\
UIGraphicsEndImageContext();\
toImageView = [[UIImageView alloc] initWithImage:toImage];\
toImageView.frame = self.navigationController.view.frame;\
[window addSubview:toImageView];\
[UIView transitionFromView:fromImageView toView:toImageView duration:0.25f options:options completion:^(BOOL finished) { \
[fromImageView removeFromSuperview];\
[toImageView removeFromSuperview];\
}\
]









//-(void)pushViewController:(UIViewController *)controller withAnimation:(UIViewAnimationOptions)options{
//    
//    FirstStep;
//    [self.navigationController pushViewController:controller animated:NO];
//    SecondStep;
//}
//-(void)popViewControllerWithAnimation:(UIViewAnimationOptions)options{
//    
//    FirstStep;
//    [self.navigationController popViewControllerAnimated:NO];
//    SecondStep;
//    
//}


/**
 *  这个方法   导致过度动画 不自然  替换成系统的方法   在view viewWillAppear  viewDidDisappear 里设置导航
 *
 *  @param controller <#controller description#>
 */
-(void)pushViewControllerWithDefaultAnimation:(UIViewController *)controller{
    
    UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    UIScrollView *sc = [[UIScrollView alloc]initWithFrame:window.frame];
    
    UIImageView *fromImageView;
    UIImageView *toImageView;
    UIGraphicsBeginImageContextWithOptions(self.navigationController.view.bounds.size, NO, [UIScreen mainScreen].scale);
    [self.navigationController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage *fromImage = UIGraphicsGetImageFromCurrentImageContext();\
    UIGraphicsEndImageContext();
    fromImageView = [[UIImageView alloc] initWithImage:fromImage];
    fromImageView.frame = self.navigationController.view.frame;
    [sc addSubview:fromImageView];
    
    [self.navigationController pushViewController:controller animated:NO];
    
    UIGraphicsBeginImageContextWithOptions(self.navigationController.view.bounds.size, NO, [UIScreen mainScreen].scale);
    [self.navigationController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *toImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    toImageView = [[UIImageView alloc] initWithImage:toImage];
    toImageView.frame = self.navigationController.view.frame;
    
    CGRect frame = toImageView.frame;
    frame.origin.x = [UIScreen mainScreen].bounds.size.width;
    toImageView.frame = frame;
    [sc addSubview:toImageView];
    
    [window addSubview:sc];
    sc.userInteractionEnabled = NO;
    
    [UIView animateWithDuration:0.3 animations:^{
        sc.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width, 0);
    } completion:^(BOOL finished) {
        [sc removeFromSuperview];
    }];
    
}





//tree end



//-(void)viewDidAppear:(BOOL)animated{
//    [super viewDidAppear:animated];
//    [self.navigationController setNavigationBarHidden:self.hiddenNAV animated:NO];
//}
//
//
//
//
//- (void) viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//  //如果导航 需要影藏  在导航将要的时候 让导航影藏
//    [self.navigationController setNavigationBarHidden:self.hiddenNAV animated:NO];
//    //界面显示  加载数据
//    //    [self loginStaeChange];
//    
//    
//}
//
//
//
//
//
//-(void)viewDidDisappear:(BOOL)animated
//{
//    [super viewDidDisappear:animated];
//    //如果导航 需要影藏  在导航已经消失的时候 让导航不影藏
//    if (self.hiddenNAV) {
////         [self.navigationController setNavigationBarHidden:!self.hiddenNAV  animated:NO];
//     [self.navigationController setNavigationBarHidden:NO animated:NO];
//    }//如果导航栏不隐藏 什么也不做
//
//}


- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:self.hiddenNAV animated:animated];
    
}
//- (void) viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//    [self.navigationController setNavigationBarHidden:!self.hiddenNAV animated:animated];
//    
//}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    //如果导航 需要影藏  在导航已经消失的时候 让导航不影藏
    //默认是no
    if (self.hiddenNAV) {
        //         [self.navigationController setNavigationBarHidden:!self.hiddenNAV  animated:NO];
             [self.navigationController setNavigationBarHidden:NO animated:NO];
            }//如果导
    

}







-(void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor =  kMainColorLightDarkGary;
    self.automaticallyAdjustsScrollViewInsets = NO;

    
}


//#ifdef __IPHONE_7_0
///**
// *  如果这么写 之前的view开始位置写64 要改成0 ,所有导航控制器包裹着的控制器 这个值默认是UIRectEdgeAll 就是控制器的范围和导航的范围是一样的 改成none 就从导航底部开始计算了
// *
// *  @return <#return value description#>
// */
//- (UIRectEdge)edgesForExtendedLayout {
//    return UIRectEdgeNone;
//}
//#endif



- (void)dealloc
{
    // 移除所有监听的通知
    
     NSLog(@"base VC  Dealloc--------------------%@---------\n------------------\n------------------------\n------------------\n",self.class);
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
